﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Primitives;
using System.Collections.Generic;
using System.ComponentModel.Composition;

namespace DomusDotNet.Sbm.Client.SL4.Infrastructure
{

    public static class MefExtensions
    {

        public static void AddService<TService, TImpl>(this CompositionBatch batch, CreationPolicy policy  = CreationPolicy.Shared)
            where TImpl : new()
        {
            var metadata = new Dictionary<string, object> {
                {
                    CompositionConstants.ExportTypeIdentityMetadataName,
                    AttributedModelServices.GetTypeIdentity(typeof(TService))
                }, 
                {
                    CompositionConstants.PartCreationPolicyMetadataName,
                    policy
                }
            };
            var exportDefinition = new ExportDefinition(AttributedModelServices.GetTypeIdentity(typeof(TService)), metadata);
            batch.AddExport(new Export(exportDefinition, () => new TImpl()));
        }

         
    }
}
